package org.springforum.forum.controller;


import io.micrometer.core.lang.NonNull;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springforum.forum.common.AppResult;
import org.springforum.forum.exception.ApplicationException;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/test")
public class TestController {

    @ApiOperation("测试接口1，显示你好Spring boot")
    @GetMapping("/hello")
    public String hello () {
        return "hello, Spring boot...";
    }

    @ApiOperation("测试接口4，按传入的姓名显示你好信息")
    @PostMapping("/helloByName")
    public AppResult helloByName (@ApiParam(value = "姓名") @RequestParam("name") @NonNull String name) {
        return AppResult.success("hello : " + name);
    }


    @ApiOperation("测试接口2，显示抛出的异常信息")
    @GetMapping("/exception")
    public String testException() throws Exception{
        throw new Exception("这是一个exception异常");
    }

    @ApiOperation("测试接口2，显示抛出的自定义的异常信息")
    @GetMapping("/appException")
    public String testApplicationException() {
        throw new ApplicationException("这是⼀个⾃定义的ApplicationException");
    }
}
